const { CleanWebpackPlugin } = require('clean-webpack-plugin');

const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');//引入path模块

// 当前的是开发环境还是生产环境
// 开发环境是production 生产环境是development
const isProd = process.env.NODE_ENV === "production";

function resolve(dir) {
    return path.resolve(__dirname, dir);
    // 项目所在的路径  当前的路径进行拼接就成为了一个绝对路径
}


module.exports = {
    mode: isProd ? "production" : "development",
    // 入口
    entry: {
        // app:"./src/main.ts"
        app: resolve('./src/main.ts')//自动拼接成绝对路径
    },
    // 出口
    output: {
        path: resolve('dist'),//当前文件的出口放到dist文件夹里
        filename: '[name].[contenthash:8].js'
        // 只截取前八位
    },
    module: {
        //配置loader
        rules: [
            {
                test: /\.([cm]?ts|tsx)$/,
                use: 'ts-loader',
                include: [resolve('src')]
            }
        ]
    },
    plugins: [
        new CleanWebpackPlugin({}),
        new HtmlWebpackPlugin({
            template: './public/index.html'
        })
    ],
    resolve: {
        extensions: ['.ts', '.tsx', '.js']
    },
    devServer: {
        open: true,
        port: 8083
    }

}